//
//  ReplyCell.m
//  sensen_ios
//
//  Created by boye_mac1 on 16/4/1.
//  Copyright © 2016年 pro. All rights reserved.
//

#import "ReplyCell.h"
#import "ZKTextImgReplaceHandle.h"
@interface ReplyCell()
{
    UIImageView *_iconImgView; // 头像
    UILabel *_nickLabel; // 昵称
    UILabel *_createTimeLabel; // 发表时间
    UILabel *_replyLabel; // 帖子内容
}
@end
@implementation ReplyCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self _initViews];
    }
    return self;
}
- (void)_initViews {
    // 头像
    _iconImgView = [[UIImageView alloc] init];
    _iconImgView.image = [UIImage imageNamed:@"defaultImage"];
    _iconImgView.clipsToBounds = YES;
    [self.contentView addSubview:_iconImgView];
    
    // 昵称
    _nickLabel = [[UILabel alloc] init];
    _nickLabel.font = FONT(15);
    _nickLabel.text = @"发帖人昵称";
    _nickLabel.textColor = rgba(12, 91, 158, 1);
    _nickLabel.textAlignment = NSTextAlignmentLeft;
    [self.contentView addSubview:_nickLabel];
    
    
    // 楼主
//    _louImage = [[UIImageView alloc] init];
//    _louImage.image = [UIImage imageNamed:@"论坛首页-详情页-楼主"];
//    [self.contentView addSubview:_louImage];
    _louLabel = [[UILabel alloc] init];
    _louLabel.layer.cornerRadius = 2.5;
    _louLabel.layer.masksToBounds = YES;
    _louLabel.backgroundColor = rgba(12, 91, 158, 1);
    _louLabel.text = @"楼主";
    _louLabel.textColor = [UIColor whiteColor];
    _louLabel.textAlignment = NSTextAlignmentCenter;
    _louLabel.font = [UIFont systemFontOfSize:11];
    [self.contentView addSubview:_louLabel];

    // 发表时间
    _createTimeLabel = [[UILabel alloc] init];
    _createTimeLabel.font = FONT(12);
    _createTimeLabel.text = @"2016-3-1 10:10:10";
    _createTimeLabel.textColor = [UIColor lightGrayColor];
    _createTimeLabel.textAlignment = NSTextAlignmentLeft;
    [self.contentView addSubview:_createTimeLabel];
    
    //回复内容
    _replyLabel = [[UILabel alloc] init];
    _replyLabel.font = FONT(15);
    _replyLabel.numberOfLines = 0;
    _replyLabel.text = @"评论内容评论内容评论内容评论内容";
    _replyLabel.textColor = [UIColor darkGrayColor];
    _replyLabel.textAlignment = NSTextAlignmentLeft;
    [self.contentView addSubview:_replyLabel];

}
#pragma mark - 重写set
- (void)setLayout:(ReplyCellFrameLayout *)layout {
    _layout = layout;
    [self _setAttributeAndLayout];
}
// 设置属性和布局
- (void)_setAttributeAndLayout {
    ReplyModel *model = _layout.model;
    
    // 设置头像
    _iconImgView.frame = _layout.iconRect;
    NSURL * url;
    if (model.authorImage != nil) {
        url = [[NSURL alloc]initWithString:model.authorImage];
    }
    [_iconImgView setImageWithURL: url placeholderImage:[UIImage imageNamed:@"defaultImage"]];
    // 设置头像圆角
    _iconImgView.layer.cornerRadius = _layout.iconRect.size.width / 2;
    
    // 设置昵称
    _nickLabel.frame = _layout.nickRect;
    _nickLabel.text = model.nickname;
    if ([_layout.model.isAllowpost intValue] == 0 && _layout.model != nil) {
        _nickLabel.text = @"禁言用户";
        _nickLabel.textColor = [UIColor lightGrayColor];
        _nickLabel.frame = _layout.nickRect2;
    }
    //楼主
//    _louImage.frame = _layout.louImageRect;
    _louLabel.frame = _layout.louImageRect;
    
    // 设置时间
    _createTimeLabel.frame = _layout.createTimeRect;
    _createTimeLabel.text = model.dateline_show;
    
    _replyLabel.frame = _layout.replyRect;
    NSMutableAttributedString *attr = [ZKTextImgReplaceHandle handleText:model.comment withRegex:nil];
    if (attr) {
        _replyLabel.attributedText = attr;
    } else {
        _replyLabel.text = model.comment;
    }
}
@end
